
#ifndef _UTILS_OS_H
#define _UTILS_OS_H

#include <sys/time.h>
#include <fcntl.h>

static inline int64_t get_sys_time()
{
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}

static inline int64_t get_sys_time_sec()
{
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (int64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}



static inline void fd_ctl_set_nonblock(int fd)
{
	int opts;
	opts=fcntl(fd, F_GETFL);
	if(opts<0) {
		perror("fcntl(fd,GETFL)");
		exit(1);
	}

	opts = opts | O_NONBLOCK;
	if(fcntl(fd, F_SETFL,opts)<0) {
		perror("fcntl(sock,SETFL,opts)");
		exit(1);
	}   
}



#endif	/* _UTILS_OS_H */
